<?php
  // no direct access
  defined( '_JEXEC' ) or die( 'Restricted access' );
  jimport( 'joomla.application.component.view');
  
  class ScheduleViewSchedule extends JView
  {              
    var $_name = "schedule";
  
    function display()
    { 
      $this->displayList();      
    }
    
    function displayList()
    {
      // sorting 
      $state =& $this->get('state');
      $lists['order_Dir'] = $state->get($this->_name . 'filter_order_Dir' );
            $lists['order']     = $state->get($this->_name . 'filter_order' );
            $this->assignRef('lists', $lists);    
    
      $schedule  = $this->getModel('schedule');
      $schedules = $schedule->get_summary_list();
      $this->assign('schedules', $schedules);
      
      $pagination = $this->get('Pagination');
      $this->assign('pagination', $pagination);
      
      JToolBarHelper::title( JText::_( 'Schedules' ), 'generic.png' );  
      
      JToolBarHelper::publishList();
      JToolBarHelper::unpublishList();
      JToolBarHelper::addNew();
      JToolBarHelper::editList();
      JToolBarHelper::deleteList();
      
      PBNYHelper::createMenu();
      
      parent::display("list");
    }
    
    function displayAdd()
    {
      $conference = $this->getModel('conference', 'conferencemodel');
      $this->assign('conferences', $conference->get());
      
      $editor =& JFactory::getEditor();
      $this->assign('editor', $editor);
      
      $venue = $this->getModel('venue', 'venuemodel');
      $this->assign('venues', $venue->get());
      
      JToolBarHelper::title( JText::_( 'Add Schedule' ), 'generic.png' );
      JToolBarHelper::save();
      JToolBarHelper::cancel();  

      parent::display("edit");
    }    
    
    function displayEdit()
    {    
      $cids = JRequest::getVar('cid', null, 'default', 'array' );
      
      $model = $this->getModel();
      $schedule = $model->get($cids[0]);
      $this->assign('schedule', $schedule);
      
      $conference = $this->getModel('conference', 'conferencemodel');
      $this->assign('conferences', $conference->get());
      
      $editor =& JFactory::getEditor();
      $this->assign('editor', $editor);
      
      $venue = $this->getModel('venue', 'venuemodel');
      $this->assign('venues', $venue->get());
      
      #needs to be revised
      $team  = $this->getModel('team', 'teammodel');
      $teams = array();
      foreach(array($schedule->first_team_id, $schedule->second_team_id) as $team_id)
        array_push($teams, $team->get($team_id));
      $this->assign('teams', $teams);

      JToolBarHelper::title( JText::_( 'Edit Schedule' ), 'generic.png' );
      JToolBarHelper::save();
      JToolBarHelper::cancel();  

      parent::display("edit");
    }
  }
?>